<template>
  <div>
    <div id="main"></div>
  </div>
</template>
<script>
export default {
  name: "c1",
  data() {
    return {
      mydata: [],
    };
  },
  mounted() {
    this.groupByBuilding();
  },
  methods: {
    groupByBuilding() {
      this.$axios.get("buildings/group").then((res) => {
        if (res.data.code == 200) {
          this.mydata = res.data.data.buildings;
          this.getChar();
        }
      });
    },
    getChar() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("main"));
      var option;
      option = {
        title: {
          text: "楼宇信息",
          subtext: "包含的楼层数",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "楼宇",
            type: "pie",

            radius: [30, 200],
            roseType: "area",
            itemStyle: {
              borderRadius: 2,
            },
            data: this.mydata,
            emphasis: {
              itemStyle: {
                shadowBlur: 2,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };

      myChart.setOption(option);
    },
  },
};
</script>
<style scoped>
#main {
  border: 0px solid rgb(255, 0, 0);
  margin-left: 260px;
  margin-top: 50px;
  width: 600px;
  height: 600px;

}
</style>
